package com.apartment.own.controller;

import java.util.List;
import java.util.Map;

import com.apartment.own.request.bills.HouseWaterBillsQuery;
import com.apartment.own.response.bill.BillsResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.apartment.common.annotation.Log;
import com.apartment.common.core.controller.BaseController;
import com.apartment.common.core.domain.AjaxResult;
import com.apartment.common.enums.BusinessType;
import com.apartment.own.domain.OwnOrdWaterBills;
import com.apartment.own.service.IOwnOrdWaterBillsService;
import com.apartment.common.utils.poi.ExcelUtil;
import com.apartment.common.core.page.TableDataInfo;

/**
 * 流水记录Controller
 *
 * @author @Dog_E
 * @date 2020-08-28
 */
@RestController
@RequestMapping("/own/bills")
@Api(value = "流水", tags = "流水")
public class OwnOrdWaterBillsController extends BaseController {
    @Autowired
    private IOwnOrdWaterBillsService ownOrdWaterBillsService;

    /**
     * 查询流水记录列表
     */
    @PreAuthorize("@ss.hasPermi('own:bills:list')")
    @PostMapping("/list")
    @ApiOperation("查询流水返回集合")
    @ApiResponses({
            @ApiResponse(code = 200,message = "ok",response = BillsResp.class)
    })
    public TableDataInfo list(@RequestBody HouseWaterBillsQuery query) {
        startPage();
        List<BillsResp> list = ownOrdWaterBillsService.selectOwnOrdWaterBillsList(query);
        return getDataTable(list);
    }

    /**
     * 新增流水记录
     */
    @PreAuthorize("@ss.hasPermi('own:bills:add')")
    @Log(title = "流水记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OwnOrdWaterBills ownOrdWaterBills) {
        return toAjax(ownOrdWaterBillsService.insertOwnOrdWaterBills(ownOrdWaterBills));
    }

    /**
     * 修改流水记录
     */
    @PreAuthorize("@ss.hasPermi('own:bills:edit')")
    @Log(title = "流水记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OwnOrdWaterBills ownOrdWaterBills) {
        return toAjax(ownOrdWaterBillsService.updateOwnOrdWaterBills(ownOrdWaterBills));
    }

    /**
     * 删除流水记录
     */
    @PreAuthorize("@ss.hasPermi('own:bills:remove')")
    @Log(title = "流水记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ownOrdWaterBillsService.deleteOwnOrdWaterBillsByIds(ids));
    }

    /**
     * 根据id获取流水信息详情
     *
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('own:bills:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("根据id查询流水详情")
    @ApiResponses({
            @ApiResponse(code = 200,message = "ok",response = BillsResp.class)
    })
    public AjaxResult getBillInfo(@PathVariable("id") String id) {
        return AjaxResult.success(ownOrdWaterBillsService.selectOwnOrdWaterBillById(id));
    }
}
